<!-- 职级编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate?'文件命名规则':'文件命名规则'"
    :visible="visible"
    width="70%"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible">
    <el-form
      :model="where"
      label-width="77px"
      class="ele-form-search">
      <el-row :gutter="15" style="padding-bottom: 15px;">
        <el-col :lg="5" :md="6">
          <el-form-item label="客户编码:">
            <el-input
              clearable
              v-model="form.customerCode"
              placeholder=""/>
          </el-form-item>
        </el-col>
        <el-col :lg="5" :md="6">
          <el-form-item label="客户名称:">
            <el-input
              clearable
              v-model="form.customerName"
              placeholder=""/>
          </el-form-item>
        </el-col>
        <el-col :lg="5" :md="6">
          <el-form-item label="发送时间:">
            <el-input
              clearable
              v-model="form.cron"
              placeholder=""/>
          </el-form-item>
        </el-col>
        <el-col :lg="5" :md="6">
          <el-form-item label="发送邮箱:">
            <el-input
              clearable
              v-model="form.email"
              placeholder=""/>
          </el-form-item>
        </el-col>
        <el-col :lg="5" :md="6">
          <el-form-item label="运行状态:">
            <el-switch
              v-model="form.status"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-value="1"
              inactive-value="0">
            </el-switch>
          </el-form-item>
        </el-col>

      </el-row>
    </el-form>

    <div slot="footer">
      <el-button
        type="primary"
        icon="el-icon-check"
        class="ele-btn-icon"
        size="small"
        @click="add">确定
      </el-button>
      <el-button @click="updateVisible(false)">关闭</el-button>

      <el-button v-if="false"
                 type="primary"
                 @click="save"
      >保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'frmInvDocList',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    dataItem: Object,

    isUpdate: Boolean
  },
  data() {
    return {
      // 表单数据
      //form: Object.assign({status: 1}, this.dataItem),
      options: [
        {
          value: "invoiceno",
          label: "发票号"
        }, {
          value: "billdate",
          label: "开票日期"
        }, {
          value: "abstract",
          label: "摘要"
        }, {
          value: "amount",
          label: "金额"
        }, {
          value: "default",
          label: "默认"
        },
      ],
      dataList: [],
      selection: [],


      // 表格列配置

      // 表格搜索条件
      where: {},
      form: {

        customerName: '',
        customerCode: '',
        email: '',
        cron: '',
        status:'0'
      },
      // 表单验证规则

      // 提交状态
      loading: false,
      // 是否是修改

    };
  },
  watch: {
    dataItem() {
      if (this.dataItem) {


        this.form.customerName = this.dataItem.customerName
        this.form.id = this.dataItem.id
        this.form.cron = this.dataItem.cron
        this.form.customerCode = this.dataItem.customerCode
        this.form.email = this.dataItem.email
      }
    }
  },

  methods: {
    /*数据上传*/
    add() {
      if (!this.form.customerCode) {
        this.$message.info("客户编码不能为空");
        return;
      }
      if (!this.form.customerName) {
        this.$message.info("客户名称不能为空");
        return;
      }
      //console.log(this.dataItem.customerCode)

      this.$message.info("准备发送")
      this.$http[this.dataItem ? 'put' : 'post'](this.dataItem ? '/invoicesendingmanagement/edit' : '/invoicesendingmanagement/add', this.form).then(res => {
          if (res.data.code === 0) {
            console.log(res.data.data)
          } else {
            this.$message.error(res.data.msg);
          }

        }
      )
      this.updateVisible(false)
      this.$emit('done');


    },
    /* 刷新表格 */
    reload() {

    }
    ,
    handleRowClick(row) {
      if (this.selection.length > 0) {
        let del_row = this.selection.shift()
        this.$refs.table.toggleRowSelection(del_row, false) //设置这一行取消选中
      }
      this.selection.push(row);
      this.$refs.table.toggleRowSelection(row, true)
    }
    ,
    select() {
      if (this.selection.length == 0) {
        this.$message.info("请选择对应规格的药品编码。");
        return;
      }
      this.$emit('update:visible', false);
      this.$emit('done', this.selection[0].zxspbm, this.selection[0].cpm);

    }
    ,
    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http[this.isUpdate ? 'put' : 'post'](this.isUpdate ? '/invoicefilenamerule/edit' : '/invoicefilenamerule/add', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              if (!this.isUpdate) {
                this.form = {};
              }
              this.updateVisible(false);
              this.$emit('done');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    }
    ,
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
</style>
